package com.xinli.business.controller;


import com.xinli.business.domain.TLbImage;
import com.xinli.business.service.ITLbImageService;
import com.xinli.common.annotation.Log;
import com.xinli.common.core.controller.BaseController;
import com.xinli.common.core.domain.AjaxResult;
import com.xinli.common.core.page.TableDataInfo;
import com.xinli.common.enums.BusinessType;
import com.xinli.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;


/**
 * 轮播图Controller
 *
 * @author ruoyi
 * @date 2024-10-13
 */
@RestController
@RequestMapping("/business/image")
public class TLbImageController extends BaseController {
    @Autowired
    private ITLbImageService tLbImageService;

    /**
     * 查询轮播图列表
     */
//@RequiresPermissions("system:image:list")
    @GetMapping("/list")
    public TableDataInfo list(TLbImage tLbImage) {
        startPage();
        List<TLbImage> list = tLbImageService.selectTLbImageList(tLbImage);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    //@RequiresPermissions("system:image:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TLbImage tLbImage) {
        List<TLbImage> list = tLbImageService.selectTLbImageList(tLbImage);
        ExcelUtil<TLbImage> util = new ExcelUtil<TLbImage>(TLbImage.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    //@RequiresPermissions("system:image:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tLbImageService.getById(id));
    }

    /**
     * 新增轮播图
     */
    //@RequiresPermissions("system:image:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLbImage tLbImage) {
        return toAjax(tLbImageService.save(tLbImage));
    }

    /**
     * 修改轮播图
     */
    //@RequiresPermissions("system:image:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLbImage tLbImage) {
        return toAjax(tLbImageService.updateById(tLbImage));
    }

    /**
     * 删除轮播图
     */
    //@RequiresPermissions("system:image:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tLbImageService.removeByIds(Arrays.asList(ids)));
    }
}
